package restaurant.selector;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Configuration {

	private final String DB_STORE = "database.store";
	private final String DB_DRIVER = "database.driver";
	private final String DB_USER = "database.user";
	private final String DB_PASSWORD = "database.password";
	private final String DB_LOGIC = "database.logic";
	private final String SERVER = "server";
	private final String SERVER_PORT = "server.port";
	private final String DB_URL = "database.url";
	
	private static final Configuration config = new Configuration();
	
	private Properties properties = new Properties();
	
	private Configuration(){
		
	}
	
	public static Configuration getInstance(){
		return config;
	}
	
	public void init( String filename ) throws IOException{
		FileInputStream fin = new FileInputStream( filename );
		properties.load(fin);
	}
	
	public String getDatabaseUrl(){ return properties.getProperty(DB_URL); }
	public String getDatabaseStore(){ return properties.getProperty(DB_STORE); }
	public String getDatabaseDriver(){ return properties.getProperty(DB_DRIVER); }
	public String getDatabaseUser(){ return properties.getProperty(DB_USER); }
	public String getDatabasePassword(){ return properties.getProperty(DB_PASSWORD); }
	public String getDatabaseLogic(){ return properties.getProperty(DB_LOGIC); }
	public boolean getServer(){ return properties.getProperty(SERVER).equalsIgnoreCase("true"); }
	public int getServerPort(){ return Integer.parseInt(properties.getProperty(SERVER_PORT)); }
}
